import pandas as pd
import numpy as np
from gpt4 import get_zx_huashu_simple



def format_DM_res(resp):
    resp = resp.replace(" ", "")
    idx_1 = resp.find('||')
    idx_2 = resp.find('#@')
    if idx_2 != -1 and idx_2 > idx_1 + 2:
        tmp1 = resp[idx_1 + 2:idx_2]
        idx_1 = resp.find('||', idx_2)
        idx_2 = resp.rfind('#@', idx_1)
        if idx_2 != -1 and idx_2 > idx_1 + 2:
            tmp2 = resp[idx_1 + 2:idx_2]
            resp = tmp1 + ' ' + tmp2
        else:
            resp = tmp1
    resp = resp.strip()
    return resp

import csv
#写入标注数据
def write_data(strs):
    # 打开文件并创建一个CSV写入器
    with open('output/zx_huashu_simple.csv', 'a', newline='') as csvfile:
        writer = csv.writer(csvfile)
        # 写入数据行
        writer.writerow(strs)



df1=pd.read_excel("sources/黑牛均分不问收入1call-0524-dm_record614.xlsx")
print(df1.shape)

for content in np.unique(df1[df1.speaker_type=='IVR'].msg_content.tolist()):
    print(content)
    res_content=format_DM_res(content)
    print(res_content)
    res_gpt4=get_zx_huashu_simple(res_content)
    print(res_gpt4)
    write_data([res_content,content,res_gpt4])


